package com.example.zzl.view.fragment.HomeFragment;


import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zzl.R;
import com.example.zzl.adapter.HomeFragment.NewsAdapter;
import com.example.zzl.databinding.HomeNewsBinding;
import com.example.zzl.model.bean.Home;
import com.example.zzl.viewmodel.HomeFragment.NewsPresenter;

import java.util.List;


public class NewsFragment extends Fragment implements NewsPresenter.NewsCallbackMv{

    private List<Home.News> list;
    private NewsAdapter adapter;
    private NewsPresenter presenter;

    public static NewsFragment newInstance(String data) {

        Bundle args = new Bundle();
        args.putString("data", data);
        NewsFragment fragment = new NewsFragment();
        fragment.setArguments(args);
        return fragment;
    }

    public NewsFragment() {

    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e("NewsFragment", "onCreate: ");
        presenter = new NewsPresenter(getActivity(), this);
        presenter.init();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        HomeNewsBinding db =DataBindingUtil.inflate(inflater, R.layout.home_news, container, false);
        Log.e("NewsFragment", "onCreateView: ");
        presenter.setDb(db);
        presenter.initView();
        return db.getRoot();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        presenter.loadData();
    }
}
